package xrc.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import xrc.service.IUserService;
import xrc.vo.LoginVo;
import xrc.vo.RespBean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

//@RestController 不能使用 否则会自动添加ResponseBody 直接返回对象 而非返回界面
@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    private IUserService userService;


    // 跳转登陆页面
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

    // 登录功能
    @RequestMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Valid LoginVo loginVo, HttpServletRequest request,
                            HttpServletResponse response) { // @Valid可以对传参进行校验
//        log.info("{}", loginVo);
        return userService.doLogin(loginVo, request, response);
    }


}
